<?php
$search = $_GET['searWords'];

if(!empty($_GET['searWords'])){
	$data = utils::gpc_check($_GET);
	/* only if REGEXP used for search....
	if(strpos($data['searWords'], ' ') !== FALSE) {
		$data['searWords'] = '(\b'.str_replace(' ','\b)|(\b',$data['searWords']).'\b)';
	}
	*/
	if (strlen($data['searWords']) < 3) {
		echo "Please insert at least 3 characters";
	} else {
		if (isset($data['page'])) {
			$page = $data['page'];
		} else {
			$page = 1;
		}
		$start = ($page-1)*20;
		//$res = mysql_query("SELECT file_name,file_title FROM bj_audio WHERE file_title  REGEXP('{$data['searWords']}') ORDER BY file_name") or die(mysql_error());
		//$res = mysql_query("SELECT file_name,file_title FROM bj_audio WHERE MATCH(file_name) AGAINST ('*{$data['searWords']}*' IN BOOLEAN MODE) ORDER BY file_name");
		$res = mysql_query("SELECT count(id_file) as nr FROM bj_audio WHERE MATCH(file_name) AGAINST ('*{$data['searWords']}*' IN BOOLEAN MODE) ORDER BY file_name");
		if ($res !== FALSE && mysql_num_rows($res)) {
			while ($lin = mysql_fetch_assoc($res)) {
				$rows = $lin['nr'];
			}
		}
		$pages = ceil($rows/20);
		$res = mysql_query("SELECT file_name,file_title FROM bj_audio WHERE MATCH(file_name) AGAINST ('*{$data['searWords']}*' IN BOOLEAN MODE) ORDER BY file_name LIMIT ".$start.",20");
		if ($res !== FALSE && mysql_num_rows($res)) {
			$cnt = 1 + ($page-1)*20;
			while ($lin = mysql_fetch_assoc($res)) {
				echo $cnt . '.&nbsp;<a href="' . utils::create_href($lin['file_title']) .'">' . str_replace('.mp3', '', $lin['file_name']) . '</a><br>';
				$cnt ++;
			}
			mysql_free_result($res);
		} else {
			echo "<b> There are no results matching your keywords.<br>Please try again.</b>";
		}
		if ($pages > 1) {
			if ($page > 1) {
				echo '<a href="'.$ABS_URL.'search.php?searWords='.$data['searWords'].'&search=Search&page='.($page-1).'"><b>Previous</b> | </a> ';
			}
			if ($page < $pages) {
				echo '<a href="'.$ABS_URL.'search.php?searWords='.$data['searWords'].'&search=Search&page='.($page+1).'"><b>Next</b></a>';
			}
		}
	}

  /*
if ($handle = opendir('./themesongs')) {
	$count = 1;
    while (false !== ($file = readdir($handle))) {
        if(strstr($file, ".mp3")) {
			if(strstr(strtolower($file), strtolower($search))) {
				echo $count.'. <a href="player.php?song='.$file.'">';
				$theFile = str_replace($search, "<font color=#cc0033 face=Arial>".$search."</font>", $file);
				$theFile = str_replace(".mp3", "", $theFile);
				echo "$theFile";
				echo "</a><br><br>";
				$count++;
			}	
    	}
	}
    closedir($handle);
}
*/
}//if empty searWords
?>

